﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace CommonTools.Extensions
{
    public static class HelperExtensions
    {
        public static void SetPropertyReflection(this object obj, string propertyName, object value)
        {
            PropertyInfo property = obj.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.SetProperty);
            if (property != null && property.PropertyType.IsAssignableFrom(value.GetType())) 
                property.SetValue(obj, value, null);
        }

        public static void AddNew(this IList list, object item)
        {
            if (!list.Contains(item)) list.Add(item);
        }

        public static bool IsEmpty(this string str)
        {
            return string.IsNullOrEmpty(str);
        }

        public static bool NotEmpty(this string str)
        {
            return !IsEmpty(str);
        }

    }
}
